<template>
    <div>
        会员姓名:
        <input type="text" v-model="name" >
        性别:
        <select  v-model="sex">
            <option value=0 >请选择</option>
            <option value=1 >男</option>
            <option value=2>女</option>
        </select>
        生日:
        <input type="date" v-model="stime">
        <input type="button" value="查询" @click="Shows">
        <table>
            <tr>
                <td>会员编号</td>
                <td>会员名称</td>
                <td>会员性别</td>
                <td>生日</td>
                <td>电话号</td>
                <td>地址</td>
                <td>操作</td>
            </tr>
            <tbody>
                <tr v-for="e in data">
                <td>{{e.Id}}</td>
                <td>{{e.Name}}</td>
                <td>{{e.Sex==1?"男":"女"}}</td>
                <td>{{moment(e.Stime).format('YYYY/MM/DD')}}</td>
                <td>{{e.Phone}}</td>
                <td>{{e.Address}}</td>
                <td>
                    <input type="button" value="删除" @click="Del(e.Id)">
                    <input type="button" value="详情" @click="XQ(e.Id)">
                    <input type="button" value="编辑" @click="Upt(e.Id)">
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import {ref,onMounted} from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter } from 'vue-router';

const router=useRouter();

const data =ref([{
    "Id": 0,
  "Name": "",
  "Sex": 0,
  "Stime": "",
  "Phone": "",
  "Address": "",
  "Delid": true
}]);

const name=ref("");
const sex=ref(0);
const stime=ref("");

onMounted(() => {
    Shows();
});

const Shows=()=>{
    axios.get("https://localhost:7146/api/Vip/GetVipAll",{params:{name:name.value,sex:sex.value,stime:stime.value}}).then(
        res=>{
            data.value=res.data;
        }
    )
}

//详情
const XQ=(vid:number)=>{
    localStorage["id"]=vid;
    location.href='/XQ';
}

//编辑
const Upt=(vid:number)=>{
    // localStorage["id"]=vid;
    // location.href='/Upt';
    router.push({path:'/Upt',query:{ID:vid}})
}

//删除
const Del=(vid:any)=>{
    if(confirm("确定要删除吗?")){
        axios.get("https://localhost:7146/api/Vip/DeleteVip",{params:{id:vid}}).then(
        res=>{
            if(res.data>0){
            alert("删除成功");
            Shows();
        }else{
            alert("删除失败");
        }
        }
    )
    }

}

</script>

<style scoped>

</style>